package com.guiji.job.controller;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.guiji.common.annotation.RepeatSubmit;
import com.guiji.common.annotation.Log;
import com.guiji.common.core.controller.BaseController;
import com.guiji.common.core.domain.AjaxResult;
import com.guiji.common.enums.BusinessType;
import com.guiji.job.vo.JobAuditRecordVo;
import com.guiji.job.bo.JobAuditRecordQueryBo;
import com.guiji.job.bo.JobAuditRecordAddBo;
import com.guiji.job.bo.JobAuditRecordEditBo;
import com.guiji.job.service.IJobAuditRecordService;
import com.guiji.common.utils.poi.ExcelUtil;
import com.guiji.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 任务审核记录Controller
 *
 * @author 钟维澎（四月）
 * @date 2021-07-02
 */
@Api(value = "任务审核记录控制器", tags = {"任务审核记录管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/auditRecord/auditRecord")
public class JobAuditRecordController extends BaseController {

    private final IJobAuditRecordService iJobAuditRecordService;

    /**
     * 查询任务审核记录列表
     */
    @ApiOperation("查询任务审核记录列表")
    @PreAuthorize("@ss.hasPermi('auditRecord:auditRecord:list')")
    @GetMapping("/list")
    public TableDataInfo<JobAuditRecordVo> list(@Validated JobAuditRecordQueryBo bo) {
        return iJobAuditRecordService.queryPageList(bo);
    }

    /**
     * 导出任务审核记录列表
     */
    @ApiOperation("导出任务审核记录列表")
    @PreAuthorize("@ss.hasPermi('auditRecord:auditRecord:export')")
    @Log(title = "任务审核记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<JobAuditRecordVo> export(@Validated JobAuditRecordQueryBo bo) {
        List<JobAuditRecordVo> list = iJobAuditRecordService.queryList(bo);
        ExcelUtil<JobAuditRecordVo> util = new ExcelUtil<JobAuditRecordVo>(JobAuditRecordVo.class);
        return util.exportExcel(list, "任务审核记录");
    }

    /**
     * 获取任务审核记录详细信息
     */
    @ApiOperation("获取任务审核记录详细信息")
    @PreAuthorize("@ss.hasPermi('auditRecord:auditRecord:query')")
    @GetMapping("/{id}")
    public AjaxResult<JobAuditRecordVo> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("id") Long id) {
        return AjaxResult.success(iJobAuditRecordService.queryById(id));
    }

    /**
     * 新增任务审核记录
     */
    @ApiOperation("新增任务审核记录")
    @PreAuthorize("@ss.hasPermi('auditRecord:auditRecord:add')")
    @Log(title = "任务审核记录", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping()
    public AjaxResult<Void> add(@Validated @RequestBody JobAuditRecordAddBo bo) {
        return toAjax(iJobAuditRecordService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改任务审核记录
     */
    @ApiOperation("修改任务审核记录")
    @PreAuthorize("@ss.hasPermi('auditRecord:auditRecord:edit')")
    @Log(title = "任务审核记录", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping()
    public AjaxResult<Void> edit(@Validated @RequestBody JobAuditRecordEditBo bo) {
        return toAjax(iJobAuditRecordService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除任务审核记录
     */
    @ApiOperation("删除任务审核记录")
    @PreAuthorize("@ss.hasPermi('auditRecord:auditRecord:remove')")
    @Log(title = "任务审核记录" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] ids) {
        return toAjax(iJobAuditRecordService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
